import 'package:shared_preferences/shared_preferences.dart';

class TokenManager {
  String? _token;
  final _key = 'enjoy_token';

 
  static TokenManager? _instance;
  TokenManager._internal();
  factory TokenManager() {
    _instance ??= TokenManager._internal();
    return _instance!;
  }

  Future<void> init() async {
    final prefs = await SharedPreferences.getInstance();
    _token = prefs.getString(_key);
  }

  Future<void> saveToken(String token) async {
    _token = token;
    final prefs = await SharedPreferences.getInstance();
    await prefs.setString(_key, token);
  }

  String? getToken() {
    return _token;
  }

  Future<void> removeToken() async {
    _token = null;
    final prefs = await SharedPreferences.getInstance();
    await prefs.remove(_key);
  }
}
